package com.ruoyi.project.syl_Fzq.controller;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.syl_Fzq.domain.Drug_Manufacturer;
import com.ruoyi.project.syl_Fzq.service.IDrug_ManufacturerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/syl_Fzq/manufacturer")
public class Drug_ManufacturerController extends BaseController {
    @Autowired
    private IDrug_ManufacturerService iDrug_manufacturerService;

    /*
     * 查询
     * */
    @PreAuthorize("@ss.hasPermi('drug:manufacturer:list')")
    @GetMapping("/list")
    public TableDataInfo list(Drug_Manufacturer drug_manufacturer) {
        startPage();
        List<Drug_Manufacturer> list = iDrug_manufacturerService.selectDrug_manufacturerList(drug_manufacturer);
        return getDataTable(list);
    }

    /*
     * 添加
     * */
    @PreAuthorize("@ss.hasPermi('drug:manufacturer:add')")
    @Log(title = "厂家管理", businessType = BusinessType.INSERT)
    @PostMapping
    //@Validated
    public AjaxResult add(@Validated @RequestBody Drug_Manufacturer drug_manufacturer) {
        drug_manufacturer.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iDrug_manufacturerService.insertDrug_Manufacturer(drug_manufacturer));
    }


    /*
     * 按条件查询
     * */

    @PreAuthorize("@ss.hasPermi('drug:manufacturer:query')")
    @GetMapping(value = "/{manufacturerId}")
    public AjaxResult getInfo(@PathVariable Long manufacturerId) {
        return AjaxResult.success(iDrug_manufacturerService.selectById(manufacturerId));
    }


    /*
     * 修改
     * */

    @PreAuthorize("@ss.hasPermi('drug:manufacturer:edit')")
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody Drug_Manufacturer drug_manufacturer) {
        drug_manufacturer.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iDrug_manufacturerService.updateManufacturer(drug_manufacturer));
    }

    /*
     * 删除
     * */
    @PreAuthorize("@ss.hasPermi('drug:manufacturer:remove')")
    @Log(title = "厂家管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{manufacturerIds}")
    public AjaxResult remove(@PathVariable Long[] manufacturerIds) {
        return toAjax(iDrug_manufacturerService.deleteManufacturerByIDs(manufacturerIds));
    }


}
